package tests;

import java.lang.System;
import java.nio.ByteBuffer;

import global.Convert;
import global.SystemDefs;

import java.io.*;
import java.util.Arrays;
import java.util.List;

import diskmgr.PCounter;
import diskmgr.Stream;

import tripleheap.InvalidSlotNumberException;
import tripleheap.InvalidTripleSizeException;
import tripleheap.THFBufMgrException;
import tripleheap.THFDiskMgrException;
import tripleheap.THFException;
import tripleheap.TScan;
import tripleheap.Triple;
import tripleheap.TripleHeapfile;
import labelheap.LScan;
import labelheap.Label;
import labelheap.LabelHeapFile;
import global.*;

public class Report {
	
	public static void main(String[] args) throws InvalidSlotNumberException, InvalidTripleSizeException, THFException, THFDiskMgrException, THFBufMgrException, Exception {
		int i = 0;
		System.out.println("\n Report...\n");
		String a = args[0];

		File file = new File(a);
		boolean exists = file.exists();
		if (exists) {
			SystemDefs.MINIBASE_RESTART_FLAG=false;
			SystemDefs sysdef = new SystemDefs(a, 0, 5500, "Clock");
		} else {
			System.out.println("DB does not exits");
		}
			
			//Stream s1=SystemDefs.JavabaseDB.openStream(a);
		LScan lscan = SystemDefs.entityLabelHeap.openLScan();
		LID lid = new LID();
		int entitylabelCnt = 0;
		while(true)
		{
			Label label = lscan.getNext(lid);
			if(label == null)
				break;
			else
			{
				entitylabelCnt++;
			}
		}
		lscan.closescan();
		LScan pscan = SystemDefs.predicateLabelHeap.openLScan();
		LID plid = new LID();
		int predicateLabelCnt = 0;
		while(true)
		{
			Label label = pscan.getNext(plid);
			if(label == null)
				break;
			else
				predicateLabelCnt++;
		}
		pscan.closescan();	
		TScan tscan = SystemDefs.tripleHeap.openScan();
		TID tid = new TID();
		int tripleCnt = 0;
		while(true)
		{
			Triple triple = tscan.getNext(tid);
			if(triple == null)
				break;
			else
				tripleCnt++;
		}
		tscan.closescan();
		System.out.println("Entity Count - " + entitylabelCnt);
		System.out.println("Predicate Count - " + predicateLabelCnt);
		System.out.println("Triple Count - "+ tripleCnt);
			SystemDefs.JavabaseDB.closeDB();
			//"db1", 0, "0", "knows","0", 0, 10   :: /home/omkarm/Desktop/data.txt 0 0 knows 0 0 10   ::  dbname 2 0 knows 0 0 100
	}

}